import Common from '../common'
var Js = Common('productLabel')
export default {
	name: 'productLabel',
	mixins:[Js],
	components: {},
	data() {
		return {

			fields: [{
					key: '',
					label: '展开',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
					width: 100
				},
				{
					key: 'title',
					label: '名称',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						style: 'width:160px;margin-right:2px;',
						placeholder: '请输入名称',
						clearable: true,
						defaultValue: '',
						optionDataName: '',
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.title = ['LIKE',['%'+val+'%']];
							} else {
								delete self.searchItem.title;
							};

						},
					},
				},
				{
					key: 'listorder',
					label: '排序',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
					listType: 'normal',
					placeholder: '请输入排序数字',
          width: 120
				},
        {
        	key: 'parentid',
        	label: '上级菜单',
        	application: ['编辑', '添加'],
        	dialogStyle: 'width:100%;',
        	componentName: 'sls-select',
        	optionsName: 'labelOptions',
        	listType: '',
        	limit: 10,
        	defaultProps: {
        		label: 'title',
        		value: 'id',
        	},
        },
				{
					key: 'mainImg',
					label: '图标',
					customSlot: 'mainImg',
					application: ['编辑', '添加'],
					componentName: 'upload',
					listType: 'normal',
					limit: 10,
					dialogStyle: 'width:90%',
					width: 200
				},
				{
					key: 'create_time',
					label: '创建时间',
					listType: 'normal',
					placeholder: '请选择创建时间',
					header_search: {
						componentName: 'sls-datetime',
						style: 'width:160px;margin-right:2px;',
						placeholder: '请选择创建时间',
						changeFunc: function(value, self) {
							if (!value) {
								delete self.searchItem.create_time;
							} else {
								self.searchItem.create_time = ['between', value = value.map(function(e) {
									return e / 1000;
								})]
							};

						},
					},
          width: 200
				},
				{
					label: '操作',
					listType: 'deal',
					width: 120
				},
			],
			// 按钮配置
			btn_info: [


				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'list',
					text: function(data) {
						return '编辑'
					},
					func: {
						apiName: function(self) {
							return "api_labelUpdate"
						},
						formData: function(self) {
							return self.formData
						},
						postData: function(self) {
							var postData = {
								searchItem: {
									id: self.formData.id,
								},
								data: self.submitData
							};
							if (self.submitData.parentid && self.submitData.parentid == self.formData.id) {
								self.$$notify('父级ID和子级ID重叠', 'fail');
								return false;
							} else {
								return postData;
							};
						}
					},
				},
				{
					type: 'danger',
					icon: 'delete',
					size: 'mini',
					funcType: 'submit',
					position: 'header',
					text: function(data) {
						return '删除选中'
					},
					func: {
						apiName: function(self) {
							return "api_labelUpdate"
						},
						postData: function(self) {
							var deleteArray = [];
							for (var i = 0; i < self.selectionArray.length; i++) {
								deleteArray.push(self.selectionArray[i].id);
							};
							var postData = {
								searchItem: {
									id: ['IN', deleteArray],
								},
								data: {
									status: -1
								}
							};
							return postData;
						}
					},
				},
				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'header',
					text: function(data) {
						return '添加'
					},
					func: {
						apiName: function(self) {
							return "api_labelAdd"
						},
						formData: function(self) {
							var data = {
								title: '',
								description: '',
								mainImg: [],
							};
							return data
						},
						postData: function(self) {
							self.submitData.type = 3;
							var postData = {
								data: self.submitData
							};
							return postData;
						}
					},
				},

			],

			searchItem: {
				type: 3,
			},
			startSearchItem: {
				type: 3,
			},
			optionData: {
				labelOptions: [],
				statusOptions: [{
					text: '启用',
					value: 1
				}, {
					text: '禁用',
					value: -1
				}],
			},
			otherData: {},
			UserInfo: {
				tableName: 'UserInfo',
				searchItem: {},
				key: 'user_no',
				middleKey: 'user_no',
				condition: 'in',
			}

		}

	},

	mounted() {
		const self = this;
		self.searchData = self.$$cloneForm(self.searchItem);
		this.init()
	},
	computed: {
		token: function() {
			return this.$store.getters.getToken
		}
	},
	methods: {

		/**
		 * 初始化
		 */
		init() {
			this.initMainData()
		},

		/**
		 * 列表主函数
		 */
		async initMainData(isNew) {

			const self = this;
			const postData = {};

			postData.token = self.$store.getters.getToken;
			if (self.searchItem) {
				postData.searchItem = self.$$cloneForm(self.searchItem)
			};
			if (JSON.stringify(self.getBefore) != "{}") {
				postData.getBefore = self.$$cloneForm(self.getBefore);
			};
			var res = await self.$$api_labelGet({
				data: postData
			});
			self.mainData = res.info.data;
			self.optionData.labelOptions = res.info.data;

		}

	},


}
